/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    overflow: hidden;
}

/* Main container - responsive height based on environment */
.container {
    width: 100%;
    height: 450px; /* Default iframe height */
    display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: 
        "controls graph"
        "controls graph"
        "info graph";
    gap: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
}

/* Detect if running in new tab (larger viewport) */
@media (min-height: 600px) {
    .container {
        height: 90vh;
    }
}

/* Control panel styling */
.control-panel {
    grid-area: controls;
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Equation display */
.equation-display {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    box-shadow: 0 2px 10px rgba(79, 70, 229, 0.3);
}

/* Controls grid */
.controls-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.control-group {
    display: grid;
    grid-template-columns: 20px 1fr 60px;
    align-items: center;
    gap: 8px;
}

.control-group label {
    font-weight: 600;
    color: #4f46e5;
    cursor: help;
}

/* Slider styling */
.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e5e7eb;
    outline: none;
    -webkit-appearance: none;
    transition: all 0.2s ease;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.4);
    transition: all 0.2s ease;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.6);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.4);
}

/* Number input styling */
.number-input {
    width: 60px;
    padding: 6px 8px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 14px;
    text-align: center;
    transition: all 0.2s ease;
}

.number-input:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Button styling */
.button-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.action-btn {
    flex: 1;
    min-width: 70px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.action-btn:active {
    transform: translateY(0);
}

/* Graph container */
.graph-container {
    grid-area: graph;
    position: relative;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border: 1px solid #e0e0e0;
    overflow: hidden;
}

/* Canvas styling */
#graph-canvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
    display: block;
}

/* Coordinate display */
.coordinate-info {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.coordinate-info.visible {
    opacity: 1;
}

/* Zoom controls */
.zoom-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.zoom-btn:hover {
    background: #4f46e5;
    color: white;
    transform: scale(1.05);
}

/* Information panel */
.info-panel {
    grid-area: info;
    background: #fff;
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.info-label {
    font-weight: 600;
    color: #4f46e5;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        grid-template-areas: 
            "controls"
            "graph"
            "info";
    }
    
    .control-panel {
        padding: 12px;
    }
    
    .controls-grid {
        gap: 12px;
    }
    
    .button-group {
        justify-content: center;
    }
    
    .action-btn {
        min-width: 80px;
        padding: 12px 16px;
        font-size: 16px;
    }
    
    .zoom-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
}

/* Touch-friendly interactions */
@media (hover: none) and (pointer: coarse) {
    .slider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    
    .zoom-btn {
        width: 44px;
        height: 44px;
    }
    
    .action-btn {
        padding: 14px 18px;
        font-size: 16px;
    }
}

/* Accessibility improvements */
.slider:focus,
.number-input:focus,
.action-btn:focus,
.zoom-btn:focus {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

/* Animation for smooth transitions */
.equation-text {
    transition: all 0.3s ease;
}

#slope-value,
#intercept-value {
    display: inline-block;
    min-width: 30px;
    text-align: center;
}